package com.cms.common;

import lombok.*;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
public class Result {


    public static final String CODE_SUCCESS = "200";
    public static final String CODE_AUTH_ERROR = "401";
    public static final String CODE_SYS_ERROR = "500";

    private int code;//编码 200/400
    //private String code;//编码 200/400
    private String msg;//成功/失败
    private Long total;//总记录数
    private Object data;//数据




    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", total=" + total +
                ", data=" + data +
                '}';
    }

    public static Result fail(){
        return result(400,"失败",0L,null);
    }


    public static Result suc(){
        return result(200,"成功",0L,null);
    }

    public static Result suc(Object data){
        return result(200,"成功",0L,data);
    }

    public static Result suc(Object data,Long total){
        return result(200,"成功",total,data);
    }

    public static Result error(String msg){
        return new Result(500,msg,0L,null);
    }
    public static Result error(String code,String msg){
        return new Result(500,msg,0L,null);
    }

    public static Result error(){
        return new Result(500,"系统错误",0L,null);
    }

    private static Result result(int code,String msg,Long total,Object data){
        Result res = new Result();
        res.setData(data);
        res.setMsg(msg);
        res.setCode(code);
        res.setTotal(total);
        return res;
    }




}
/*
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Result {


    public static final String CODE_SUCCESS = "200";
    public static final String CODE_AUTH_ERROR = "401";
    public static final String CODE_SYS_ERROR = "500";


     //请求返回的编码 200 401 404 500
     //编码表示这次成功或者失败
    //或者说可以看出失败的类型

    private String code;//编码 200/400

    //表示错误的详细信息

    private String msg;//成功/失败

     //承载你返回的数据

    private Object data;//数据


    public static Result suc(){
        return Result.builder().code(CODE_SUCCESS).msg("请求成功").build();
    }

    public static Result suc(Object data){
        return new Result(CODE_SUCCESS,"请求成功",data);
    }

    public static Result error(String msg){
        return new Result(CODE_SYS_ERROR,msg,null);
    }

    public static Result error(String code,String msg){
        return new Result(code,msg,null);
    }

    public static Result error(){
        return new Result(CODE_SYS_ERROR,"系统错误",null);
    }


}
*/

